package com.sgb.kjwl.view.ui.adapter.supplier3;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.user.PromoteGoodsEntity;
import com.sgb.kjwl.utils.LocationUtil;
import com.sgb.kjwl.view.widget.RoundImageView;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * @author Administrator
 */
public class PromoteGoodsAdapter extends BaseRecycleAdapter<PromoteGoodsEntity> {

    public PromoteGoodsAdapter(Context context, List<PromoteGoodsEntity> datas) {
        super(context, R.layout.item_promote_goods, datas);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void convert(ItemViewHolder holder, final PromoteGoodsEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView promotePrice = holder.getItem().findViewById(R.id.promote_price);
        promotePrice.setText("￥" + entity.getPromotePrice() + "/" + entity.getUnit());

        TextView price = holder.getItem().findViewById(R.id.price);
        price.setText("￥" + entity.getPrice() + "/" + entity.getUnit());
        price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);

        RoundImageView goodsImg = holder.getItem().findViewById(R.id.goods_img);
        Glide.with(context).load(entity.getImgUrl()).into(goodsImg);

        ImageView imageView = holder.getItem().findViewById(R.id.image_ziying);
        if ("1".equals(entity.getSelfSupportTag())) {
            imageView.setVisibility(View.VISIBLE);
        } else {
            imageView.setVisibility(View.GONE);
        }

        if (LocationUtil.isOpenLocation(context) && LocationUtil.currentLocationIsValid()) {
            holder.getItem().findViewById(R.id.tv_distance).setVisibility(View.VISIBLE);
        } else {
            holder.getItem().findViewById(R.id.tv_distance).setVisibility(View.GONE);
        }
    }

}
